<?php
if(isset($_GET['iyuutoken'])&& !empty($_GET['iyuutoken'])&& $_GET['iyuutoken']!= 'undefined'){
    $iyuutoken = $_GET['iyuutoken'];
}else{
    echo "请配置iyuutoken值";
    exit();
}
if(isset($_GET['hash']) && !empty($_GET['hash'])&& $_GET['hash']!= 'undefined') {
  $hash = $_GET['hash'];
} else {
  echo "请配置种子hash值";
  exit();
}
$data = getCurl($hash,$iyuutoken);

function getCurl($hash,$iyuutoken){
    $sites = '{
        "sites": [
            {
                "id": 1,
                "site": "keepfrds",
                "nickname": "朋友",
                "base_url": "pt.keepfrds.com",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 2,
                "site": "pthome",
                "nickname": "铂金家",
                "base_url": "pthome.net",
                "download_page": "download.php?id={}&uid={uid}&hash={hash}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 3,
                "site": "m-team",
                "nickname": "馒头",
                "base_url": "kp.m-team.cc",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 4,
                "site": "hdsky",
                "nickname": "天空",
                "base_url": "hdsky.me",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "cookie",
                "is_https": 2
            },
            {
                "id": 5,
                "site": "tjupt",
                "nickname": "北洋",
                "base_url": "tjupt.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 6,
                "site": "pter",
                "nickname": "猫站",
                "base_url": "pterclub.com",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 7,
                "site": "hdhome",
                "nickname": "家园",
                "base_url": "hdhome.org",
                "download_page": "download.php?id={}&uid={uid}&hash={hash}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 8,
                "site": "btschool",
                "nickname": "学校",
                "base_url": "pt.btschool.club",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 9,
                "site": "ourbits",
                "nickname": "我堡",
                "base_url": "ourbits.club",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 10,
                "site": "hddolby",
                "nickname": "杜比",
                "base_url": "www.hddolby.com",
                "download_page": "download.php?id={}&uid={uid}&hash={hash}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 11,
                "site": "torrentccf",
                "nickname": "他吹吹风",
                "base_url": "et8.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 12,
                "site": "ptmsg",
                "nickname": "马杀鸡",
                "base_url": "pt.msg.vg",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 14,
                "site": "ttg",
                "nickname": "听听歌",
                "base_url": "totheglory.im",
                "download_page": "dl/{}/{passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 15,
                "site": "nanyangpt",
                "nickname": "南洋",
                "base_url": "nanyangpt.com",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 17,
                "site": "hdcity",
                "nickname": "城市",
                "base_url": "hdcity.city",
                "download_page": "download?id={}&cuhash={cuhash}",
                "reseed_check": "cookie",
                "is_https": 2
            },
            {
                "id": 18,
                "site": "nicept",
                "nickname": "老师",
                "base_url": "www.nicept.net",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 19,
                "site": "52pt",
                "nickname": "52pt",
                "base_url": "52pt.site",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 21,
                "site": "beitai",
                "nickname": "备胎",
                "base_url": "www.beitai.pt",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 22,
                "site": "eastgame",
                "nickname": "吐鲁番",
                "base_url": "pt.eastgame.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 23,
                "site": "ssd",
                "nickname": "春天",
                "base_url": "springsunday.net",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 24,
                "site": "soulvoice",
                "nickname": "聆音",
                "base_url": "pt.soulvoice.club",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 25,
                "site": "chdbits",
                "nickname": "彩虹岛",
                "base_url": "chdbits.co",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 26,
                "site": "leaguehd",
                "nickname": "柠檬",
                "base_url": "lemonhd.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 27,
                "site": "ptsbao",
                "nickname": "烧包",
                "base_url": "ptsbao.club",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 28,
                "site": "hdchina",
                "nickname": "瓷器",
                "base_url": "hdchina.org",
                "download_page": "download.php?hash={hash}",
                "reseed_check": "cookie",
                "is_https": 2
            },
            {
                "id": 29,
                "site": "hdarea",
                "nickname": "好大",
                "base_url": "www.hdarea.co",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 30,
                "site": "hdtime",
                "nickname": "时光",
                "base_url": "hdtime.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 31,
                "site": "1ptba",
                "nickname": "1ptba",
                "base_url": "1ptba.com",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 32,
                "site": "hd4fans",
                "nickname": "兽",
                "base_url": "pt.hd4fans.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 33,
                "site": "opencd",
                "nickname": "皇后",
                "base_url": "open.cd",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 36,
                "site": "joyhd",
                "nickname": "开心",
                "base_url": "www.joyhd.net",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 37,
                "site": "dmhy",
                "nickname": "幼儿园",
                "base_url": "u2.dmhy.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 38,
                "site": "upxin",
                "nickname": "好多油",
                "base_url": "pt.upxin.net",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 39,
                "site": "oshen",
                "nickname": "奥申",
                "base_url": "www.oshen.win",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 40,
                "site": "discfan",
                "nickname": "蝶粉",
                "base_url": "discfan.net",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 41,
                "site": "hdzone",
                "nickname": "高清地带",
                "base_url": "hdzone.me",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 44,
                "site": "hdbd",
                "nickname": "伊甸园",
                "base_url": "pt.hdbd.us",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 45,
                "site": "byr",
                "nickname": "北邮人",
                "base_url": "byr.pt",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 47,
                "site": "ccfbits",
                "nickname": "吹吹风",
                "base_url": "ccfbits.org",
                "download_page": "feeddownload.php/{}/{passkey}/{}.torrent",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 48,
                "site": "hdbits",
                "nickname": "海德堡",
                "base_url": "hdbits.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "",
                "is_https": 2
            },
            {
                "id": 49,
                "site": "ptpbd",
                "nickname": "PTP",
                "base_url": "passthepopcorn.me",
                "download_page": "torrents.php?action=download&authkey={authkey}&torrent_pass={torrent_pass}&id={}",
                "reseed_check": "torrent_pass,authkey",
                "is_https": 2
            },
            {
                "id": 50,
                "site": "hd-torrents",
                "nickname": "核弹头",
                "base_url": "hd-torrents.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "",
                "is_https": 2
            },
            {
                "id": 51,
                "site": "dicmusic",
                "nickname": "海豚",
                "base_url": "dicmusic.club",
                "download_page": "torrents.php?action=download&id={}&authkey={authkey}&torrent_pass={torrent_pass}",
                "reseed_check": "torrent_pass,authkey",
                "is_https": 2
            },
            {
                "id": 52,
                "site": "skyeysnow",
                "nickname": "天雪",
                "base_url": "skyey2.com",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 53,
                "site": "pt",
                "nickname": "葡萄",
                "base_url": "pt.sjtu.edu.cn",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 54,
                "site": "hdroute",
                "nickname": "路",
                "base_url": "www.hdroute.org",
                "download_page": "download.php?id={}&passkey={passkey}&from=rss",
                "reseed_check": "passkey",
                "is_https": 0
            },
            {
                "id": 56,
                "site": "haidan",
                "nickname": "海胆",
                "base_url": "www.haidan.video",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 57,
                "site": "hdfans",
                "nickname": "红豆饭",
                "base_url": "hdfans.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 58,
                "site": "dragonhd",
                "nickname": "龙之家",
                "base_url": "www.dragonhd.xyz",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 59,
                "site": "hitpt",
                "nickname": "百川",
                "base_url": "www.hitpt.com",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 60,
                "site": "pttime",
                "nickname": "时间",
                "base_url": "www.pttime.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 2
            },
            {
                "id": 61,
                "site": "hdai",
                "nickname": "海带",
                "base_url": "www.hd.ai",
                "download_page": "download.php?id={}&uid={uid}&hash={hash}",
                "reseed_check": "passkey,uid",
                "is_https": 2
            },
            {
                "id": 62,
                "site": "npupt",
                "nickname": "蒲公英",
                "base_url": "npupt.com",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 63,
                "site": "hdatmos",
                "nickname": "阿童木",
                "base_url": "hdatmos.club",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 64,
                "site": "greatposterwall",
                "nickname": "海豹",
                "base_url": "greatposterwall.com",
                "download_page": "torrents.php?action=download&id={}&authkey={authkey}&torrent_pass={torrent_pass}",
                "reseed_check": "torrent_pass,authkey",
                "is_https": 1
            },
            {
                "id": 65,
                "site": "hdpost",
                "nickname": "普斯特",
                "base_url": "pt.hdpost.top",
                "download_page": "torrent/download/{}.{rsskey}",
                "reseed_check": "rsskey",
                "is_https": 1
            },
            {
                "id": 66,
                "site": "hares",
                "nickname": "大白兔",
                "base_url": "club.hares.top",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 67,
                "site": "hudbt",
                "nickname": "蝴蝶",
                "base_url": "hudbt.hust.edu.cn",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 68,
                "site": "audiences",
                "nickname": "观众",
                "base_url": "audiences.me",
                "download_page": "download.php?id={}&downhash={downHash}",
                "reseed_check": "downHash",
                "is_https": 1
            },
            {
                "id": 69,
                "site": "piggo",
                "nickname": "猪猪网",
                "base_url": "piggo.me",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 70,
                "site": "wintersakura",
                "nickname": "冬樱",
                "base_url": "wintersakura.net",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 71,
                "site": "hdpt",
                "nickname": "明教",
                "base_url": "hdpt.xyz",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 72,
                "site": "hhanclub",
                "nickname": "憨憨",
                "base_url": "hhanclub.top",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 73,
                "site": "gainbound",
                "nickname": "丐帮",
                "base_url": "gainbound.net",
                "download_page": "download.php?id={}",
                "reseed_check": "passkey,cookie",
                "is_https": 1
            },
            {
                "id": 74,
                "site": "hdvideo",
                "nickname": "高清视频",
                "base_url": "hdvideo.one",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 75,
                "site": "pt0ffcc",
                "nickname": "自由农场",
                "base_url": "pt.0ff.cc",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 76,
                "site": "redleaves",
                "nickname": "红叶",
                "base_url": "leaves.red",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 77,
                "site": "pt2xfree",
                "nickname": "2xFree",
                "base_url": "pt.2xfree.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 78,
                "site": "sharkpt",
                "nickname": "鲨鱼",
                "base_url": "sharkpt.net",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 79,
                "site": "ptchina",
                "nickname": "铂金学院",
                "base_url": "ptchina.org",
                "download_page": "download.php?id={}&passkey={passkey}",
                "reseed_check": "passkey",
                "is_https": 1
            },
            {
                "id": 80,
                "site": "zhuque",
                "nickname": "朱雀",
                "base_url": "zhuque.in",
                "download_page": "api/torrent/download/{}/{torrent_key}",
                "reseed_check": "torrent_key",
                "is_https": 1
            }
        ]
    }
    ';
    $hash = array($hash);
    $hash = json_encode($hash);
    $sha1 = sha1($hash);
    $curl = curl_init();
    $data = [
        'sign' => $iyuutoken,
        'timestamp' => '1625068800',
        'version' => '2.0.0',
        'hash' => $hash,
        'sha1' => $sha1,

    ];
    curl_setopt_array($curl, array(
    CURLOPT_URL => 'http://api.iyuu.cn/index.php?service=App.Api.Hash',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $data,
    CURLOPT_HTTPHEADER => array(
        'User-Agent: Apifox/1.0.0 (https://www.apifox.cn)',
        'Accept: */*',
        'Host: api.iyuu.cn',
    ),
    ));
    $response = curl_exec($curl);
    curl_close($curl);
    // 将 JSON 格式的字符串转换为 PHP 数组
    $data = json_decode($response, true);
    $sitesJson = json_decode($sites, true);
    // 提取 sid 和 torrent_id
    $sid_list = array();
    $torrent_id_list = array();
    $site_list = array();
    foreach ($data['data'] as $item) {
        foreach ($item['torrent'] as $torrent) {
            $sid_list[] = $torrent['sid'];
            $torrent_id_list[] = $torrent['torrent_id'];
            foreach ($sitesJson['sites'] as $site) {
                if($site['id'] == $torrent['sid']){
                    $site_list[] = $site['base_url'];
                }
            }
        }
    }
    $list = array();
    foreach($site_list as $key => $value){
        $list[] = "https://".$value ."/details.php?id=".$torrent_id_list[$key];
    }
    // 输出结果
    echo json_encode($list);
}
?>